# 生成可执行文件的名称
Target = lcd_carama_demo
ARCH ?= arm

# 编译器CC
ifeq ($(ARCH), x86)
	CC = gcc
else
	CC = arm-linux-gnueabihf-gcc
endif

# 存放中间文件的路径
build_dir = build_$(ARCH)

# 源文件和头文件的绝对路径
src_dir = /home/ignite/Linux_APPlication/Socket/source
inc_dir = /home/ignite/Linux_APPlication/Socket/include

# 源文件
sources = $(wildcard $(src_dir)/*.c) lcd_carama.c

# 目标文件（*.o）
objects = $(patsubst %.c,$(build_dir)/%.o,$(notdir $(sources)))

# 头文件
includes = $(wildcard $(inc_dir)/*.h)

# 编译参数
CFLAGS = $(patsubst %, -I%, $(inc_dir))

# 链接过程
$(build_dir)/$(Target) : $(objects) | create_build
	$(CC) $^ -o $@ -lpthread

# 编译工程
$(build_dir)/%.o : $(src_dir)/%.c $(includes) | create_build
	$(CC) -c $(CFLAGS) $< -o $@ 

$(build_dir)/lcd_carama.o : lcd_carama.c $(includes) | create_build
	$(CC) -c $(CFLAGS) $< -o $@ 

.PHONY: clean cleanall check create_build

clean:
	rm -rf $(build_dir)

cleanall:
	rm -rf build_x86 build_arm

check:
	@echo $(CFLAGS)
	@echo $(CURDIR)
	@echo $(src_dir)
	@echo $(sources)
	@echo $(objects)

create_build:
	@mkdir -p $(build_dir)
